<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>题库添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.8/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <form id="myadd" class="layui-form layui-form-pane" lay-submit
          lay-filter="userForm" enctype="multipart/form-data">

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>题目类别</label>
            <div class="layui-input-block">
                <input type="radio" name="major" value="Java" lay-skin="primary" title="Java" checked="">
                <input type="radio" name="major" value="HTML5" lay-skin="primary" title="HTML5">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>题目级别</label>
            <div class="layui-input-block">
                <input type="radio" name="level" value="1" lay-skin="primary" title="简单" checked="">
                <input type="radio" name="level" value="2" lay-skin="primary" title="普通">
                <input type="radio" name="level" value="3" lay-skin="primary" title="困难">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">题目类型</label>
            <div class="layui-input-block">
                <input type="text" name="seg"  placeholder="请输入竞赛题目类型" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="save" type="button" class="layui-btn" lay-submit lay-filter="formUser">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script src="/static/lib/layui-v2.6.8/layui.js" charset="utf-8"></script>
<script>
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return 1;
    }
    // console.log("uid=hhh"+getUrlParam("id"))

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(formUser)', function (data) {
            data.field.perid = getUrlParam("uid");
            // console.log(data.field)
            $.ajax({
                url: '/exam/examAdd',
                data: data.field,
                type: "post",
                success: function () {
                    alert("添加竞赛试题成功")
                    //重新加载父页面
                    parent.location.reload();

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }
            })
            return false;
        });
    });
</script>
</body>
</html>